package com.burry.action;

import java.util.List;
import java.util.Map;

import com.burry.services.CatalogService;
import com.burry.util.MapList;

public class CataAction extends BaseAction {
	private MapList cataList = null;
	
	private String id = null;
	private String code = null;
	private String cataName = null;
	private String treeStr = null;
	private String pid = null;
	private String viewOrder = null;
	private String isNav = null;
	private String isUpdate = null;
	private String cataAd = null;
	private String isFake = null;
	
	public String getIsFake() {
		return isFake;
	}

	public void setIsFake(String isFake) {
		this.isFake = isFake;
	}

	public String getIsNav() {
		return isNav;
	}

	public void setIsNav(String isNav) {
		this.isNav = isNav;
	}

	public String getIsUpdate() {
		return isUpdate;
	}

	public void setIsUpdate(String isUpdate) {
		this.isUpdate = isUpdate;
	}

	public String getCataAd() {
		return cataAd;
	}

	public void setCataAd(String cataAd) {
		this.cataAd = cataAd;
	}

	public String getViewOrder() {
		return viewOrder;
	}

	public void setViewOrder(String viewOrder) {
		this.viewOrder = viewOrder;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getTreeStr() {
		return treeStr;
	}

	public void setTreeStr(String treeStr) {
		this.treeStr = treeStr;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getCataName() {
		return cataName;
	}

	public void setCataName(String cataName) {
		this.cataName = cataName;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public MapList getCataList() {
		return cataList;
	}

	public void setCataList(MapList cataList) {
		this.cataList = cataList;
	}

	public String listCata(){
		//CatalogService cs = new CatalogService();
		CatalogService.reload();
		this.cataList = CatalogService.allFaCataInfo;
		CatalogService cs = new CatalogService();
		treeStr = cs.getTreeStr(cataList);
		return SUCCESS;
	}
	
	public String updateCataInit(){
		Map tmp = (Map)CatalogService.allCataInfo.get(id);
		code = (String)tmp.get("cata_code");
		cataName = (String)tmp.get("cata_name");
		id = (String)tmp.get("fa_code");
		viewOrder = (String)tmp.get("view_order");
		return SUCCESS;
	}
	
	public String updateCata(){
		CatalogService cs = new CatalogService();
		cs.updateCatalog(code, id, cataName,viewOrder,isFake);
		return SUCCESS;
	}
	
	public String deleteCata(){
		CatalogService cs = new CatalogService();
		cs.delACatalog(id);
		return SUCCESS;
	}
	
	public String addCata(){
		CatalogService cs = new CatalogService();
		cs.addACatalog(id, code, cataName,viewOrder,isFake);
		return SUCCESS;
	}
	
	public String cataAdInit(){
		CatalogService cs = new CatalogService();
		List cataAds = cs.getCataAd(id);
		if(cataAds != null && cataAds.size() != 0){
			Map tmp = (Map)cataAds.get(0);
			code = (String)tmp.get("cata_code");
			isNav = (String)tmp.get("isNav");
			isUpdate = "true";
			cataAd = (String)tmp.get("ad_content");
		}else{
			code = id;
			isUpdate = "false";
		}
		return SUCCESS;
	}
	
	public String saveCataAd(){
		CatalogService cs = new CatalogService();
		cs.addOrUpdateAd(code, cataAd, isNav, isUpdate);
		return SUCCESS;
	}
}
